package org.opens.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.opens.entity.ShiroUser;
import org.opens.service.ShiroUserService;
import org.opens.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api/user")
public class ShiroUserController {

    @Autowired
    private ShiroUserService shiroUserService;

    @GetMapping(value = "/page")
    public PageResult<ShiroUser> page(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "limit", defaultValue = "10") Integer limit,
            @RequestParam(value = "name", defaultValue = "", required = false) String name
    ) {
        PageResult<ShiroUser> pageResult = new PageResult<>();
        ShiroUser param = new ShiroUser();
        param.setName(name);
        IPage<ShiroUser> pageDate = shiroUserService.page(page, limit, param);
        pageResult.setCode(0);
        pageResult.setMsg("分页成功");
        pageResult.setCount(pageDate.getTotal());
        pageResult.setData(pageDate.getRecords());
        return pageResult;
    }

}
